"""
执行用例
"""
import unittest, time
import os
import HTMLTestRunner

# 或者将HTMLTestRunner文件拷贝到Python安装目录里的Lib文件夹下
# 获取路径
from ecshop.utils.Config import Config

file = './config/config.ini'
config = Config(file)

cur_path = os.path.dirname(os.path.realpath(__file__))
print(cur_path)
# 测试用例路径
case_path = os.path.join(cur_path, 'testcase')
print(case_path)
# 测试报告路径
report_path = os.path.join(cur_path, 'report')
print('xxxxx' + report_path)

if __name__ == "__main__":
    # 构造测试集
    suite = unittest.defaultTestLoader.discover(case_path, 'Test*.py')
    # 获取当前时间
    now = time.strftime('%Y-%m-%d %H_%M_%S')

    #文件名
    filename = report_path + '\\' + now + ' HTMLReport.html'

    fp = open(filename,'wb')
    # 定义测试报告
    runner = HTMLTestRunner.HTMLTestRunner(title='接口测试报告',
                                           description='用例执行情况：',
                                           stream=fp,
                                           verbosity=2
                                           )

    # 运行测试用例
    runner.run(suite)
    fp.close()

    # mail = Mail(config.get_value(file,'email','smtpserver'), 25)
    # #self.config.get_value(self.file,'system','url')
    # mail_user = config.get_value(file,'email','mail_user')
    # # 密码(部分邮箱为授权码)
    # mail_pass = config.get_value(file,'email','mail_pass')
    # mail.login(mail_user, mail_pass)
    # mail.add_attachment('./report/' + now + ' HTMLReport.html')
    #
    # subject = config.get_value(file,'email','subject')
    # to_addr = config.get_value(file,'email','to_addr')
    # content = config.get_value(file,'email','content')
    # mail.send(subject, content, to_addr)



